import request from '@/utils/request'

// 登录
export function login(data) {
    return request({
        url: '/user/login',
        method: 'post',
        data
    })
}

// 退出登录
export function logout() {

    return request({
        url: '/user/logout',
        method: 'get',
    })
}
// 通过token获取用户信息
export function getUser() {
    return request({
        url: '/user/info',
        method: 'get',
    })
}

//通过id获取用户信息
export function getUserById(id) {
    return request({
        url: '/back/users/' + id,
        method: 'get',
    })
}

//通过crp获取用户信息
export function getUserByCRP(crp) {
    return request({
        url: '/back/users/findByCRP/' + crp,
        method: 'get',
    })
}


// 传送ticket到后端
export function sendTicket(ticket) {
    return request({
        url: '/user/login/' + ticket,
        method: 'get',
    })
}

// 修改用户信息
export function editUser(data) {
    return request({
        url: '/back/users/update',
        method: 'post',
        data
    })
}
// 获取用户收藏
export function getCollection() {
    return request({
        url: '/user/collect/list',
        method: 'get',
    })
}

// 添加用户收藏
export function addCollection(id) {
    return request({
        url: `/user/collect/add?appId=${id}`,
        method: 'post',
    })
}

// 删除用户收藏
export function deleteCollection(id) {
    return request({
        url: `/user?appId=${id}`, // 将 appId 作为查询参数
        method: 'delete',
    });
}
